<div class="akordeon-item review-rating-form">
    <div class="akordeon-item-head">
        <div class="akordeon-item-head-container">
            <div class="akordeon-heading">
                <?php echo $this->__('Write Your Own Review') ?>
            </div>
        </div>
    </div>
    <div class="akordeon-item-body">
        <div class="akordeon-item-content">
        <?php if ($this->getAllowWriteReviewFlag()): ?>
        <form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
            <fieldset>
                <?php echo $this->getChildHtml('form_fields_before')?>
                <h3><?php echo $this->__("You're reviewing:"); ?> <span><?php echo $this->htmlEscape($this->getProductInfo()->getName()) ?></span></h3>
                <?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
                    <h4><?php echo $this->__('How do you rate this product?') ?> <em class="required">*</em></h4>
                    <span id="input-message-box"></span>
                    <div class="rating-block">
                    <?php $rating_count = 0; ?>
                    <?php foreach ($this->getRatings() as $_rating): ?>
                        <p>
                            <?php $rating_count++; ?>
                            <span class="rating-type"><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></span>
                            <span>
                            <?php foreach ($_rating->getOptions() as $_option): ?>
                                <input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio rating-star rating-star-<?php echo $rating_count ?>" />
                            <?php endforeach; ?>
                            </span>
                        </p>
                    <?php endforeach; ?>
                    </div>
                    <input type="hidden" name="validate_rating" class="validate-rating" value="" />
                    <div class="clearer"></div>
                <?php endif; ?>
                    <ul class="form-list">
                        <li>
                            <label for="nickname_field" class="required"><em>*</em><?php echo $this->__('Nickname') ?></label>
                            <div class="input-box">
                                <input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getNickname()) ?>" />
                            </div>
                        </li>
                        <li>
                            <label for="summary_field" class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
                            <div class="input-box">
                                <input type="text" name="title" id="summary_field" class="input-text required-entry" value="<?php echo $this->htmlEscape($data->getTitle()) ?>" />
                            </div>
                        </li>
                        <li>
                            <label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
                            <div class="input-box">
                                <textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
                            </div>
                        </li>
                    </ul>
                </fieldset>
                <div class="buttons-set">
                    <button type="submit" title="<?php echo $this->__('Submit Review') ?>" class="button"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
                </div>
        </form>
        <script type="text/javascript">
        //<![CDATA[
            var dataForm = new VarienForm('review-form');
            Validation.addAllThese(
            [
                   ['validate-rating', '<?php echo $this->__('Please select one of each of the ratings above') ?>', function(v) {
                        var trs = $('product-review-table').select('tr');
                        var inputs;
                        var error = 1;
        
                        for( var j=0; j < trs.length; j++ ) {
                            var tr = trs[j];
                            if( j > 0 ) {
                                inputs = tr.select('input');
        
                                for( i in inputs ) {
                                    if( inputs[i].checked == true ) {
                                        error = 0;
                                    }
                                }
        
                                if( error == 1 ) {
                                    return false;
                                } else {
                                    error = 1;
                                }
                            }
                        }
                        return true;
                    }]
            ]
            );
            jQuery(document).ready(function(){
                <?php for($i = 1; $i <= $rating_count; $i++){ ?>
                    jQuery('.rating-star-<?php echo $i ?>').rating();
                <?php } ?>
                jQuery('.review-rating-form button').click(function(){
                    document.getElementById('review-form').submit();
                });
            })
        //]]>
        </script>
        <?php else: ?>
        <p class="review-nologged" id="review-form">
            <?php echo $this->__('Only registered users can write reviews. Please, <a href="%s">log in</a> or <a href="%s">register</a>', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
        </p>
        <?php endif ?>
    </div>
</div>
